package com.ruihua.controller;

import com.ruihua.pojo.Result;
import com.ruihua.pojo.TIndexSetting;
import com.ruihua.service.ITIndexSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@CrossOrigin//解决跨域
@Api(tags = "指标框架制定")
public class TIndexSettingControlller {

    @Resource
    private ITIndexSettingService indexSettingService;

    @ApiOperation("查指标全部数据")
    @GetMapping("/allindex")
    public Result selectAll(){
        return indexSettingService.TIndexSettingAll();
    }

    @ApiOperation("按照年份查找")
    @GetMapping("/selectindex")
    @ApiImplicitParam(name = "year", value = "年份", required = false, dataType = "Integer", paramType = "query")
    public Result selectindex(int year){
        return indexSettingService.selectTIndexSetting(year);
    }


    @ApiOperation("添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "levelOneIndex", value = "一级指标", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "levelTwoName", value = "二级指标", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "siginForTime", value = "签收时限", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "attachmentContent", value = "附件内容", required = false, dataType = "string", paramType = "query")
    })
    @PostMapping("/addindex")
    public Result addIndex( TIndexSetting tIndexSetting) {
        return indexSettingService.addITIndexSetting(tIndexSetting);
    }

    @ApiOperation("查询指标信息")
    @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "string", paramType = "query")
    @GetMapping("/getindex")
    public Result getIndex(String id) {
        return indexSettingService.getTIndexSetting(id);
    }

    @ApiOperation("修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "levelOneIndex", value = "一级指标", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "levelTwoName", value = "二级指标", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "siginForTime", value = "签收时限", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "attachmentContent", value = "附件内容", required = false, dataType = "string", paramType = "query")
    })
    @PostMapping("/updateindex")
    public Result updateIndex( TIndexSetting tIndexSetting) {
        return indexSettingService.updateTIndexSetting(tIndexSetting);
    }

    @ApiOperation("下发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "IssuingUnit", value = "一级指标", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "Integer", paramType = "query")
    })
    @PostMapping("/issueindex")
    public Result issueIndex(String issuingUnit, String id) {
        return indexSettingService.issue(issuingUnit,id);
    }

    @ApiOperation("删除")
    @ApiImplicitParam(name = "id", value = "id", required = false, dataType = "string", paramType = "query")
    @PostMapping("/deleteindex")
    public Result deleteIndex(String id) {
        return indexSettingService.deleteIndex(id);
    }
}
